package org.example.SystemDemo.comment.res;

import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.serializer.ToStringSerializer;
import lombok.Data;
import org.example.SystemDemo.comment.enity.*;

import java.util.List;


/**
 * 返回信息列表
 */
@Data
public class HostinfoListRES {

    private static String NullsUsed = "0.00%";
    private static String NioUser = "0";

    public HostinfoListRES(HostInfo info){
        this.id = info.getId();
        this.connectStatus = info.isConnectStatus();
        this.hostName = info.getHostName();
    }

    public HostinfoListRES(HostInfo info, CPU cpu, Memory memory, List<Net> nets, List<Disk> disks) {
        this(info);
        this.setCpuUsed(cpu.getCpuCurrentUsage());
        this.setMemoryUsed(memory.getMemoryUsage());
        this.setNitInput(nets.get(0).getNetRecv().toString());
        this.setNitOutput(nets.get(0).getNetSent().toString());
        this.setDiskUsed(disks.get(0).getUsage());
    }

    @JSONField(serializeUsing = ToStringSerializer.class)
    private Long id;

    private String hostName;

    private boolean connectStatus;

    private String cpuUsed = NullsUsed;

    private String memoryUsed = NullsUsed;

    private String nitInput = NioUser;

    private String nitOutput = NioUser;

    private String diskUsed = NullsUsed;

    private String nitUnit = "kb";
}
